﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.CustomSettings;
using YaAppoint.Response;

namespace YaAppoint.Web.Controllers
{
    public class CustomSettingController(ICustomSettingAppService customSettingAppService) : AbpController
    {
        private readonly ICustomSettingAppService _customSettingAppService = customSettingAppService;

        /// <summary>
        /// 加载到诊模式选项
        /// </summary>
        [HttpGet("/api/custom-setting/get-check-in-mode")]
        public ActionResult GetCheckInMode()
        {
            return new JsonResult(_customSettingAppService.GetCheckInModeOptions());
        }


        /// <summary>
        /// 加载his号段选项
        /// </summary>
        [HttpGet("/api/custom-setting/get-his-interval-span-options")]
        public ActionResult GetHisIntervalSpanOptions()
        {
            return new JsonResult(_customSettingAppService.GetHisIntervalSpanOptions());
        }

        /// <summary>
        /// 获取设计详情
        /// 
        /// 使用场景：  自定义设置页面专用！！
        /// </summary>
        [HttpGet("/api/custom-setting/get-setting-detail")]
        public async Task<IActionResult> GetSettingDetail(SettingLevel level, Guid? depId,Guid? deviceTypeId,Guid? deviceId)
        {
            return new JsonResult(await _customSettingAppService.GetSetting(level,depId,deviceTypeId,deviceId));
        }

        /// <summary>
        /// 保存设置
        /// </summary>
        [HttpPost("/api/custom-setting/save")]
        public async Task<IActionResult> Save([FromBody]CustomSettingDto dto)
        {
            return new JsonResult(await _customSettingAppService.Save(dto));
        }

        /// <summary>
        /// 获取左边栏树形数据
        /// </summary>
        [HttpGet("/api/custom-setting/get-tree-data")]
        public async Task<IActionResult> GetTreeData(Guid? depId)
        {
            return new JsonResult(await _customSettingAppService.GetLeftTreeData(depId));
        }

        /// <summary>
        /// 获取设备自定义设置
        ///
        /// 使用场景：  1、手动预约加载号池   2、自动预约加载号池
        /// </summary>
        [HttpGet("/api/custom-setting/get-device-setting")]
        public async Task<IActionResult> GetDeviceSetting(Guid deviceId)
        {
            var res = new BackJson()
            {
                code = 0,
                data = await _customSettingAppService.GetDeviceSetting(deviceId)
            };
            return new JsonResult(res);
        }


    }
}
